<template>
  <a-layout-header class="header-box">
    <div class="logo-box flot-left" :style="{width: !collapsed?200+'px':64+'px'}">
      <div class="logo">
        <img :src="DI_MINI_LOGO" v-if="collapsed" style="height: 100%">
        <img :src="DI_LOGO" v-else style="height: 100%">
      </div>
    </div>

    <menu-unfold-outlined
        v-if="collapsed"
        class="trigger"
        @click="onCollapsed"
    />
    <menu-fold-outlined v-else class="trigger" @click="onCollapsed"/>

    <div style="float: right;margin-right: 40px">
      <span class="m-r-10">欢迎您！{{ getUserInfo?.realName }}</span>
      <a-dropdown>
        <a-avatar :src="getUserInfo?.avatar" style="cursor: pointer"/>
        <template #overlay>
          <a-menu>
            <a-menu-item>
              <a href="javascript:;" @click="go('/cds-center/index')">个人中心</a>
            </a-menu-item>
            <a-menu-item>
              <a href="javascript:;" @click="handleLoginOut">退出登录</a>
            </a-menu-item>
          </a-menu>
        </template>
      </a-dropdown>
    </div>

    <div style="float: right;margin-right: 40px">
      <a-button type="link" @click="go('/')" link>
        <shop-outlined />
        门户网站
      </a-button>
    </div>
  </a-layout-header>
</template>

<script lang="ts">
export default {
  name: "c-header"
}
</script>

<script lang="ts" setup>
import {ref} from "vue";
import {useUserStore} from "/@/store/modules/user";
import DI_LOGO from '/@/assets/logo.png'
import DI_MINI_LOGO from '/@/assets/logo-mini.png'
import {storeToRefs} from "pinia";
import {useGo} from "/@/hooks/web/usePage";

const userStore = useUserStore();
const {getUserInfo} = storeToRefs(userStore);
const emit = defineEmits(['collapsedChange']);
const collapsed = ref<boolean>(false)
const go = useGo();

function onCollapsed() {
  collapsed.value = !collapsed.value
  emit('collapsedChange', collapsed.value)
}

//  login out
function handleLoginOut() {
  userStore.confirmLoginOut();
}

</script>

<style lang="less" scoped>
.trigger {
  font-size: 18px;
  line-height: 64px;
  padding: 0 24px;
  cursor: pointer;
  transition: color 0.3s;
}


.trigger:hover {
  color: @theme-hover-color;
}


.header-box {
  padding: 0;
  background: #fff;
  z-index: 10;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;


  .logo-box {
    background-color: #001529;
    height: 64px;
    width: 200px;
    max-height: 200px;
    min-width: 80px;
    text-align: center;
    transition: .21s;

    .logo {
      display: inline-block;
      height: 35px;
    }
  }

  .logout {
    cursor: pointer;
    float: right;
    width: 80px;
    height: 100%;
    z-index: 10 !important;
  }

}


</style>
